package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.CategoryService;
import com.atguigu.spzx.model.entity.product.Category;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("admin/product/category")
@Tag(name = "商品分类模块")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @GetMapping("findByParentId/{parentId}")
    @Operation(summary = "根据父id查询商品分类信息")
    public Result<List<Category>> findByParentId(@PathVariable Long parentId){
        List<Category> list=categoryService.findByParentId(parentId);
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }

    @GetMapping("exportData")
    @Operation(summary = "导出分类数据到Excel文件")
    public  void exportData(HttpServletResponse response){
        categoryService.exportData(response);
    }
    @PostMapping("importData")
    @Operation(summary = "导入Excel文件中的分类数据")
    public Result importData(MultipartFile file){
        categoryService.importData(file);
        return Result.build(null,ResultCodeEnum.SUCCESS).setMsg("导入成功");
    }
}

